import java.util.Scanner;
class TreeNode1 {
    char val;
    TreeNode1 left;
    TreeNode1 right;
    TreeNode1() {}
    TreeNode1(char val) {
        this.val = val;
    }
    TreeNode1(char val, TreeNode1 left, TreeNode1 right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
public class TestMain {

    public static int i = 0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String st = in.nextLine();
            TreeNode1 root = new TreeNode1();
            root = creatTree(st);
            inorder(root);
        }
    }
    public static TreeNode1 creatTree(String str) {
        TreeNode1 root = null;
        if(str.charAt(i) != '#') {
            root = new TreeNode1(str.charAt(i));
            i++;
            root.left = creatTree(str);
            root.right = creatTree(str);
        } else {
            i++;
        }
        return root;
    }
    public static void inorder(TreeNode1 root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val+" ");
        inorder(root.right);
    }
}
